package com.lhh.userservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhh.springcommon.annotation.WebLog;
import com.lhh.springcommon.annotation.WithRequestId;
import com.lhh.springcommon.entity.Follow;
import com.lhh.springcommon.entity.vo.UserVO;
import com.lhh.springcommon.utils.PageQuery;
import com.lhh.springcommon.utils.Response;
import com.lhh.userservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 关注
 * @author 李厚航
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/follow")
public class FollowController {


    private final UserFollowService userFollowService;


    @Autowired
    public FollowController(UserFollowService userFollowService) {
        this.userFollowService = userFollowService;
    }

    /**
     * 查询用户关注数或粉丝数
     * @return 关注数
     */
    @GetMapping("/countFollow")
    @WithRequestId
    @WebLog
    public Response<Long> countFollow(@RequestParam(value = "uid",required = false) Integer uid,
                                      @RequestParam(value = "fid",required = false) Integer fid){
        return Response.success(userFollowService.countFollow(uid,fid));
    }

    /**
     * 分页查询关注和粉丝信息
     * @param page
     * @return
     */
    @GetMapping("/queryFans")
    @WithRequestId
    @WebLog
    public Response<Page<UserVO>> queryFans(@RequestParam("page") Integer page,
                                            @RequestParam("pageSize") Integer pageSize,
                                            @RequestParam(value = "uid",required = false) Integer uid,
                                            @RequestParam(value = "fid",required = false) Integer fid)  {
        return Response.success(userFollowService.queryPageFans(page,pageSize,uid,fid));
    }

    /**
     * 关注或取消关注
     * @return
     */
    @PostMapping("/addOrDeleteFollow")
    @WithRequestId
    @WebLog
    public Response<Boolean> addOrDeleteFollow(@RequestBody Follow follow){
        return Response.success(userFollowService.addOrDeleteFollow(follow));
    }

    /**
     * 查询关注信息和粉丝信息
     * @param page
     * @return
     */
    @GetMapping("/queryFollow")
    @WithRequestId
    @WebLog
    public Response<Page<UserVO>> queryFollow(@RequestParam("page") Integer page,
                                              @RequestParam("pageSize") Integer pageSize,
                                              @RequestParam(value = "uid",required = false) Integer uid,
                                              @RequestParam(value = "fid",required = false) Integer fid){
        return Response.success(userFollowService.queryPageFollow(page,pageSize,uid,fid));
    }

    /**
     * 查询是否关注
     * @param fid
     * @return
     */
    @GetMapping("/isFollow")
    @WithRequestId
    @WebLog
    public Response<Boolean> isFollow(@RequestParam("uid") Integer uid,@RequestParam(value = "fid") Integer fid){
        return Response.success(userFollowService.isFollow(uid,fid));
    }
}
